package followme.yaohuile.com.followme.parsejson.recommend;

import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;

import org.json.JSONException;
import org.json.JSONObject;

import followme.yaohuile.com.followme.bean.recommend.Recommend;
import followme.yaohuile.com.followme.network.recommend.NetWork;
import followme.yaohuile.com.followme.utils.LogUtils;

/**
 * Created by Administrator on 15-11-14.
 */
public class ParserRecommend {
    public static void getData(final String url, final Handler handler){
        Log.d("ParserRecommend",url);
        if(!TextUtils.isEmpty(url)){
            NetWork.getNetData(url, new RequestCallBack<String>() {
                @Override
                public void onSuccess(ResponseInfo<String> responseInfo) {
                    String json = responseInfo.result;
                    LogUtils.LOG_D(getClass(),"首页URL = "+json);
                    if (json != null) {
                        try {
                            JSONObject object = new JSONObject(json);
                            Recommend recommend = JSON.parseObject(object.toString(), Recommend.class);
                            Message message = new Message();
                            message.what = 0x123;
                            message.obj = recommend;
                            handler.sendMessage(message);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }

                @Override
                public void onFailure(HttpException e, String s) {

                }
            });
        }
    }
}
